﻿Imports System
Imports System.Threading
Imports System.Workflow.ComponentModel

Namespace System.Workflow.Runtime
    Friend Class WorkflowDefinitionLock
        Implements IDisposable
        ' Methods
        Public Sub New(ByVal definition As Activity)
            Me._syncObj = WorkflowDefinitionLock.GetWorkflowDefinitionLockObject(definition)
            Monitor.Enter(Me._syncObj)
        End Sub

        Public Sub Dispose()
            Monitor.Exit(Me._syncObj)
        End Sub

        Friend Shared Function GetWorkflowDefinitionLockObject(ByVal dependencyObject As Object) As Object
            Return [TryCast](dependencyObject,DependencyObject).GetValue(WorkflowDefinitionLock.WorkflowDefinitionLockObjectProperty)
        End Function

        Friend Shared Sub SetWorkflowDefinitionLockObject(ByVal dependencyObject As Object, ByVal value As Object)
            [TryCast](dependencyObject,DependencyObject).SetValue(WorkflowDefinitionLock.WorkflowDefinitionLockObjectProperty, value)
        End Sub


        ' Fields
        Private _syncObj As Object
        Friend Shared ReadOnly WorkflowDefinitionLockObjectProperty As DependencyProperty = DependencyProperty.RegisterAttached("WorkflowDefinitionLockObject", GetType(Object), GetType(WorkflowDefinitionLock), New PropertyMetadata(DependencyPropertyOptions.NonSerialized))
    End Class
End Namespace

